package controller;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

/**
 * Creat with IntelliJ IDEA
 * Description:
 * User:WZW
 * Date:2022-08-07
 * Time:20:48
 */
@WebServlet("/logout")
public class LogoutServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //先找到会话
        HttpSession session = req.getSession(false);
        if (session == null) {
            resp.getWriter().write("用户尚未登录，无法注销！");
            return;
        }
        //删除会话中信息
        session.removeAttribute("user");
        resp.sendRedirect("login.html");
    }
}
